<?php


//FELIPE y Laurent
class ArticlesController extends AppController {

    var $name = 'Articles';
    var $helpers = array('Html', 'Javascript');
    var $components = array('Auth');

     function beforeFilter(){
          parent::beforeFilter();
        $this->Auth->userModel = 'admin';
        $this->Auth->fields = array('username' => 'user', 'password' => 'mot-passe');
        $this->Auth->allow('article');
        $this->Auth->loginAction = array('controller' => 'admins', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
        $this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
    }


    function ajouter_articles() {
        $f = $this->data;
        $form = $this->data;

        if (empty($this->data) == false) {

            $resultat = $this->Article->save($form);
            if ($resultat) {
                echo "<script> alert('Lien Enregistré');</script>";

                echo "<script lenguage='javascript'>";
                echo "location='ajouter_articles'";
                echo "</script>";
            }
        }
    }

    function article(){
        return $this->Article->find('all');
        
    }

      function liste_editer_lien(){

         $this->set('articles', $this->Article->find('all'));


     }

      function modifier_lien_final($id_article){

        $this->Article->id = $id_article;
        $this->Article->id;
        $this->set('articles', $this->Article->read());


     }

     function modifier_complete_lien() {


        $form = $this->data;
        $ima = $this->data;

       

	if (empty($this->data)==false) {
		//print_r ($this->data);

		//$this->Fichier->id = $id_art;
		$resultat = $this->Article->save($form);

	if ($resultat) {
			 echo "<script> alert('Lien Modifie');</script>";

                echo "<script lenguage='javascript'>";
                echo "location='liste_editer_lien'";
                echo "</script>";
		}
            }

    }

   function effacer_liens(){

      $this->set('articles', $this->Article->find('all'));
    }



   function effacer_liens_final($id_article) {
        $this->Article->id = $id_article;
        $this->Article->id;
        $this->set('articles', $this->Article->read());
    }



       function effacer_liens_completo(){
        $form=$this->data;
        $id=$form['Article']['id'];
        if (!empty($this->data)) {

            $resultat = $this->Article->delete($id);
            if ($resultat) {
                echo "<script> alert('Lien Effacé');</script>";

                echo "<script lenguage='javascript'>";
                echo "location='effacer_liens'";
                echo "</script>";
            }
        }

 }

}
?>